package com.xsh.sawsynth;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SawSynthEventHandler
{
    private final Context pluginContext;
    private static String tag = "SawSynthEventHandler";

    Class<?> SlEngine;
    public SawSynthEventHandler(Context context)
    {
        this.pluginContext = context;
    }
    public SawSynthEventHandler(Context context,Class<?> slEngine) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        this.pluginContext = context;
        SlEngine = slEngine;
    }
    public void setAmplitude(int progress) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        double volume = progress / 100.0;
       // Log.d(tag,"setAmplitude: " + volume);
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParam",String.class,double.class);
        method.invoke(null,"setAmplitude",volume);
        //2025/6/4 测试通过 在主app反射类给eventHandler调用到cpp层
        /*Method method = SlEngine.getDeclaredMethod("pluginEventHandlerTest");
        method.voke(null);*/
    }
    public void setDetune(int progress) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        double detune = progress;
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParam",String.class,double.class);
        method.invoke(null,"setDetune",detune);
    }
}
